/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_car_info.web;




import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.tb_car_info.entity.TbCarInfo;
import com.thinkgem.jeesite.modules.tb_car_info.service.TbCarInfoService;

/**
 * 车辆管理Controller
 * @author ZhangYangZe
 * @version 2017-05-14
 */
@Controller
@RequestMapping(value = "${adminPath}/tb_car_info/tbCarInfo")
public class TbCarInfoController extends BaseController {

	@Autowired
	private TbCarInfoService tbCarInfoService;
	/**
	 * 获取单条数据
	 * @param String id
	 * @return TbCarInfo
	 */
	@ModelAttribute
	public TbCarInfo get(@RequestParam(required=false) String id) {
		TbCarInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbCarInfoService.get(id);
		}
		if (entity == null){
			entity = new TbCarInfo();
		}
		return entity;
	}
	/**
	 * 查询分页数据
	 * @param TbCarInfo
	 * @param Model
	 * @param HttpServletRequest
	 * @return String
	 */
	@RequiresPermissions("tb_car_info:tbCarInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbCarInfo tbCarInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbCarInfo> page = tbCarInfoService.findPage(new Page<TbCarInfo>(request, response), tbCarInfo); 
		model.addAttribute("page", page);
		return "modules/tb_car_info/tbCarInfoList";
	}
	
	@RequiresPermissions("tb_car_info:tbCarInfo:view")
	@RequestMapping(value = "form")
	public String form(TbCarInfo tbCarInfo, Model model) {
		model.addAttribute("tbCarInfo", tbCarInfo);
		return "modules/tb_car_info/tbCarInfoForm";
	}
	/**
	 * 添加或修改车辆
	 * @param TbCarInfo
	 * @param Model
	 * @param RedirectAttributes
	 * @return String
	 */
	@RequiresPermissions("tb_car_info:tbCarInfo:edit")
	@RequestMapping(value = "save")
	public String save(TbCarInfo tbCarInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbCarInfo)){
			return form(tbCarInfo, model);
		}
		tbCarInfoService.save(tbCarInfo);
		addMessage(redirectAttributes, "保存车辆成功");
		return "redirect:"+Global.getAdminPath()+"/tb_car_info/tbCarInfo/?repage";
	}
	/**
	 * 删除车辆
	 * @param TbCarInfo
	 * @param RedirectAttributes
	 * @return String
	 */
	@RequiresPermissions("tb_car_info:tbCarInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(TbCarInfo tbCarInfo, RedirectAttributes redirectAttributes) {
		tbCarInfoService.delete(tbCarInfo);
		addMessage(redirectAttributes, "删除车辆成功");
		return "redirect:"+Global.getAdminPath()+"/tb_car_info/tbCarInfo/?repage";
	}
		
	
	/**
	 * 获取车辆详情
	 * @param TbCarInfo
	 * @param HttpServletRequest
	 * @param HttpServletResponse
	 * @param Model
	 * @return ArrayList<TbCarInfo>
	 */
	@RequestMapping("carDetails")
	@ResponseBody
	public ArrayList<TbCarInfo> carDetails(TbCarInfo tbCarInfo , HttpServletRequest request , HttpServletResponse response , Model model) {
		String carnum=request.getParameter("id");
		ArrayList<TbCarInfo> tbcarinfo= tbCarInfoService.carDetails(carnum);
		return tbcarinfo;
	}

}